package com.zxkj.domain.dao;

import com.zxkj.domain.entity.Addr;
import com.zxkj.domain.entity.SciAu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2018/3/14.
 */
@Service
public class SciDeptDao {
    @Autowired
    @Qualifier("primaryJdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    /**
     * 根据deptId获取sci_au_id和fullname
     * @param deptId
     * @return
     */
    public List<SciAu> getAuNameByFullnameByDeptId(Integer deptId) {
        StringBuilder sb = new StringBuilder();
        sb.append("SELECT sci_au.au_id,fullname FROM sci_au ");
        sb.append("INNER JOIN sci_map_au_ad ");
        sb.append("on sci_au.au_id=sci_map_au_ad.au_id ");
        sb.append("INNER JOIN sci_map_dept_ad ");
        sb.append("on sci_map_au_ad.ad_id=sci_map_dept_ad.ad_id ");
        sb.append("WHERE dept_id=? ");
        return jdbcTemplate.query(sb.toString(), new BeanPropertyRowMapper(SciAu.class), deptId);
    }

    /**
     * 根据corpId获取sci_au_id和fullname
     * @param corpId
     * @return
     */
    public List<SciAu> getAuNameByFullnameByCorpId(Integer corpId) {
        StringBuilder sb = new StringBuilder();
        sb.append("SELECT sci_au.au_id,sci_au.fullname FROM sci_au ");
        sb.append("INNER JOIN sci_map_au_ad ");
        sb.append("on sci_au.au_id=sci_map_au_ad.au_id ");
        sb.append("INNER JOIN sci_map_ad_corporation ");
        sb.append("on sci_map_au_ad.ad_id=sci_map_ad_corporation.ad_id ");
        sb.append("WHERE corp_id=? ");
        return jdbcTemplate.query(sb.toString(), new BeanPropertyRowMapper(SciAu.class), corpId);
    }
}
